package com.generator.code.util;

import com.generator.code.model.GenTableEntity;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.cglib.beans.BeanMap;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author guoq.z
 * @date 2021/4/2
 */
public class Test {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        GenTableEntity genTableEntity = new GenTableEntity();
        genTableEntity.setTableName("aaaaa");

        BeanWrapper beanWrapper = new BeanWrapperImpl(genTableEntity);
        PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();

        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            String name = propertyDescriptor.getName();
            System.out.println(name);
        }

        System.out.println("---------------------------------");

        Field[] declaredFields = GenTableEntity.class.getDeclaredFields();
        for (Field field : declaredFields) {

            String name = field.getName();
            System.out.println(name);

            field.setAccessible(true);
            Object o = field.get(genTableEntity);
            System.out.println(o);
        }

        GenTableEntity genTableEntity1 = GenTableEntity.class.newInstance();
        System.out.println(genTableEntity1);

        BeanMap beanMap = BeanMap.create(genTableEntity1);
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "ZHANG");

        beanMap.putAll(map);

        System.out.println(genTableEntity1);


    }
}
